import { Module } from "vuex";
import { GlobalDataProps } from "./index";
export interface TemplateProps {
  id: number;
  title: string;
  coverImg: string;
  author: string;
  copiedCount: number;
}
export const testData: TemplateProps[] = [
  {
    id: 1,
    coverImg:
      "https://static.imooc-lego.com/upload-files/screenshot-889755.png",
    title: "测试标题1",
    author: "captern",
    copiedCount: 1,
  },
  {
    id: 2,
    coverImg:
      "https://static.imooc-lego.com/upload-files/screenshot-889755.png",
    title: "测试标题2",
    author: "captern",
    copiedCount: 2,
  },
  {
    id: 3,
    coverImg:
      "https://static.imooc-lego.com/upload-files/screenshot-889755.png",
    title: "测试标题3",
    author: "captern",
    copiedCount: 3,
  },
];
export interface TemplatesProps {
  data: TemplateProps[];
}

const templates: Module<TemplatesProps, GlobalDataProps> = {
  state: {
    data: testData,
  },
  getters: {
    // getTemplateById: (state, getters, rootState) => (id: number) => {
    //   console.log("getters", getters);
    //   console.log("rootState", rootState);
    //   return state.data.find((t) => t.id === id);
    // },
    getTemplateById: (state) => (id: number) => {
      return state.data.find((t) => t.id === id);
    },
  },
};

export default templates;
